****************
*** Unpacking the Local Resource Curse: How Externalities and Governance Shape Social Conflict
*** Renard Sexton
*** August 2019
*** Version 1.0
*** Replication code
***************

/* Data accessed in this replication file:

resource_curse_merged.dta
pollution_dataset.dta
margins_domestic.dta
margins_multinational.dta
margins1.dta
China_imports_and_prices.dta
institutions.dta
*/

/* Version History
1.0  August 2019 -- Replication files for article in Journal of Conflict Resolution shared on Dataverse & journal website
*/

*** Created in STATA/MP version 16.0

clear all
set more off

** Change to appropriate working directory (e.g.)

cd "~/Downloads/"

** Set scheme, temporarily
set scheme s1mono

** install eststo
net install st0085_2

********************
* Variable Labels 
********************

capture program label_var1
label var mineral_price_index "Standardized department-specific international mineral price index"
label var ambiental "Number of environmentally related conflict incidents"
label var ambiental2 "environmentally related conflict incidents? (dummy)"
label var ihs_ambiental "Number of environmentally related conflict incidents (IHS transformed)"
label var rechazo "Number of conflict incidents rejecting mining"
label var ihs_rechazo "Number of conflict incidents rejecting mining (IHS transformed)"
label var beneficio "Number of conflict incidents demanding benefits from mining"
label var ihs_beneficio "Number of conflict incidents demanding benefits from mining (IHS transformed)"
label var year "Year"
label var department "Department or 'Region' of Peru"
label var totalmines "Total number of mines/processing facilities in 2001"
label var ihs_totalmines "Total number of mines/processing facilities in 2001 (IHS transformed)"
label var price_index_acute "Department-specific international mineral price index (Acute Polluters Only)"
label var price_index_chronic "Department-specific international mineral price index (Chronic Polluters Only)"
label var acute_total "Total number of mines/processing facilities in 2001 (Acute Polluters Only)"
label var chronic_total "Total number of mines/processing facilities in 2001 (Chronic Polluters Only)"
label var ihs_acute_total "Total number of mines/processing facilities in 2001 (Acute Polluters Only, IHS transformed)"
label var ihs_chronic_total "Total number of mines/processing facilities in 2001 (Chronic Polluters Only, IHS transformed)"
label var acute_under5_respiratory_pc "Acute under-5 respiratory admissions per 1,000 population"
label var adult_chickens_pc "Number of adult chickens in livestock census per 1,000 human population"
label var very_competitive "Competitive election (5 percent winning margin or smaller) in most recent regional election?"
label var pct_executed "Percent of regional budget executed"
label var price_index_new2006 "Standardized department-specific international mineral price index (mines established 2005-2006)"
label var post_eiti "Dummy for post-2009 (EITI report released)"
label var election "Dummy for election year"
foreach x in copper gas gold iron lead oil silver tin zinc{
label var `x'_s "Standardized price for `x'"
label var `x'_sum "Number of `x' mines"
}
label var ihs_ambiental_neighbor_total "Number of environmentally related conflict incidents (in neighboring departments, IHS transformed)"
label var ihs_non_mining_neighbor_total "Number of non-mining-related conflict incidents (in neighboring departments, IHS transformed)"
label var price_index_adj "Standardized dept-specific price index, rescaled so minimum is zero"
label var ln_non_mining "Number of non-mining-related conflict incidents (log+1)"
label var mineral_price_index_domestic "Standardized department-specific international mineral price index (Domestic Peruvian firms only)"
label var mineral_price_index_mnc "Standardized department-specific international mineral price index (Foreign firms only)"
label var combined_pc2 "Combined Tax Transfers to Department Government"
label var amount_per_mining_provice2 "Govt spending in mining zones (per mining prov.)"
label var amount_per_mine2 "Govt spending in mining zones (per mine.)"
label var local_pc "Local jobs in mining per 1,000 population"
label var pbi_pc2 "GDP per capita"
label var L_mineral_price_index "Standardized department-specific international mineral price index (t-1)"
label var L_pct_executed "Percent of regional budget executed (t-1)"
label var ihs_enviro "Number of environmentally related conflict incidents (machine-coded)"
label var ihs_clash "Number of terrorist/insurgent conflict incidents (IHS transformed))"
end

capture program label_var2
label var mine_price_index "Standardized mine-specific international mineral price index"
label var year "Year"
label var company "Owner of mine"
label var location "Location of mine"
label var river "River being tested for water pollution"
label var commodities "Which commodities produced at the mine?"
label var ph "pH level detected in river near mine"
label var ln_cyanide_pollution "cyanide concentration detected near mine (log transformed)"
label var mine_id "Facility id number"
label var acute "Does mine include acute polluters? (gold, tin, oil)"
end



********************
* Manuscript Tables
********************

use resource_curse_merged.dta,clear
tsset department year
label_var1

** Table 1. Unconditional results: Environmental, General rejection, Benefits-sharing
eststo clear
xtreg ihs_ambiental cL.mineral_price_index i.year, fe vce(cl department)
eststo
xtreg ihs_rechazo cL.mineral_price_index i.year, fe vce(cl department)
eststo
xtreg ihs_beneficio cL.mineral_price_index i.year, fe vce(cl department)
eststo

esttab using "table1.tex",  keep(L.mineral_price_index)  cells(b(star fmt(2)) se(par fmt(2))) stats(N, labels(N) fmt(0)) starlevel(* .05 ** .01 *** .001) replace tex nolz label noabb wrap varwidth(50) mtitles


** Table 2. Effects scaled by number of mines 


qui xtreg ihs_ambiental cL.mineral_price_index cL.mineral_price_index#c.ihs_totalmines i.year, fe vce(cl department)
margins, dydx(L.mineral_price_index) at(ihs_totalmines=(0.88137 2.312438 2.998223  3.68950 )) post
test 2._at = 3._at 

qui xtreg ihs_rechazo cL.mineral_price_index cL.mineral_price_index#c.ihs_totalmines i.year, fe vce(cl department)
margins, dydx(L.mineral_price_index) at(ihs_totalmines=(0.88137 2.312438 2.998223  3.68950 )) post
test 2._at = 3._at 

qui xtreg ihs_beneficio cL.mineral_price_index cL.mineral_price_index#c.ihs_totalmines i.year, fe vce(cl department)
margins, dydx(L.mineral_price_index) at(ihs_totalmines=(0.88137 2.312438 2.998223  3.68950 )) post
test 2._at = 3._at 


*** Table 3. Acute vs Chronic Polluting Mines

xtreg ihs_ambiental  L.price_index_acute cL.price_index_acute#c.ihs_acute_total L.price_index_chronic cL.price_index_chronic#c.ihs_chronic_total i.year, fe vce(cl department)

margins, dydx(L.price_index_acute L.price_index_chronic) at(ihs_acute_total=( 1.4436 2.0947 2.6441 2.9982) ihs_chronic_total=( 1.4436 2.0947 2.6441 2.9982)) post
test [L.price_index_acute]1._at = [L.price_index_chronic]1._at
test [L.price_index_acute]6._at = [L.price_index_chronic]6._at
test [L.price_index_acute]11._at = [L.price_index_chronic]11._at
test [L.price_index_acute]16._at = [L.price_index_chronic]16._at


*** Table 4. Prices for acute polluters greatly increase levels of water pollution
use pollution_dataset.dta, clear
tsset mine_id year

qui xtreg ph cL.mine_price_index cL.mine_price_index#acute i.year, fe vce(cl mine_id)
margins,dydx(L.mine_price_index) at(acute=(0 1 ))

qui xtreg ln_cyanide_pollution cL.mine_price_index cL.mine_price_index#acute i.year, fe vce(cl mine_id)
margins,dydx(L.mine_price_index) at(acute=(0 1 ))


*** Table 5. Negative effects on child health and livestock

use resource_curse_merged.dta,clear
tsset department year
label_var1

foreach y in  acute_under5_respiratory_pc adult_chickens_pc  {
xtreg `y'  L.price_index_acute cL.price_index_acute#c.ihs_acute_total ///
 L.price_index_chronic cL.price_index_chronic#c.ihs_chronic_total i.year, fe vce(cl department)
eststo
margins, dydx(L.price_index_acute) at(ihs_acute_total=( 1.4436 2.0947 2.6441 2.9982)) 
margins, dydx(L.price_index_chronic) at(ihs_chronic_total=( 1.4436 2.0947 2.6441 2.9982))
}

*** Figure 3. Treatment effects of commodity prices on conflict, by electoral competitiveness and government capacity

xtreg ihs_ambiental cL.mineral_price_index##very_competitive i.year, fe vce(cl department)
margins, dydx(L1.mineral_price_index) at(very_competitive=(0 1) ) post
marginsplot, yline(0) plotop(connect(none)  mcolor(gs2)   ) ciopts(lcolor(gs2)   lwidth(thick) lpattern(dash)  )   xscale(range( -0.5 1.5 )) ///
xtitle("Low Competition                                High Competition") xlabel(none) ///
title("")  ytitle("Average Treatment Effect") ylabel(-.75(.25).75) l(90)


xtreg ihs_ambiental cL.mineral_price_index##cL.pct_executed i.year, fe vce(cl department)
margins, dydx(L1.mineral_price_index) at(cL.pct_executed=(.84 .92 ) ) post
marginsplot, yline(0) plotop(connect(none)  mcolor(gs2)   ) ciopts(lcolor(gs2)   lwidth(thick) lpattern(dash)  )   xscale(range(0.80 0.96)) ///
     xtitle("Low Capacity                        High Capacity") xlabel(none) ///
title("")  ytitle("Average Treatment Effect") ylabel(-.75(.25).75) l(90)

*** Figure 4. Good local governance mitigates the pollution from price increases for acute polluters
use pollution_dataset.dta, clear
tsset mine_id year

xtreg ph cL.mine_price_index##cL2.pct_executed cL.mine_price_index##cL2.pct_executed#c.acute i.year, fe vce(cl mine_id)
margins, dydx(L.mine_price_index) at(cL2.pct_executed=(.84 .92 ) acute=(1)) 

marginsplot, yline(0) level(90) plotop(connect(none)  mcolor(gs2)   ) ciopts(lcolor(red)   lwidth(thick) lpattern(dash)  )   xscale(range(0.80 0.96)) ///
     xtitle("Low Capacity                           High Capacity") xlabel(none) ///
title("pH by acute polluting mines")  ytitle("Average Treatment Effect") ylabel(-1(.5)1)

xtreg ln_cyanide_pollution cL.mine_price_index##cL2.pct_executed cL.mine_price_index##cL2.pct_executed#c.acute i.year, fe vce(cl mine_id)
margins, dydx(L.mine_price_index) at(cL2.pct_executed=(.84  .92 ) acute=(1))

marginsplot, yline(0) level(90) plotop(connect(none)  mcolor(gs2)   ) ciopts(lcolor(blue)   lwidth(thick) lpattern(dash)  )   xscale(range(0.80 0.96)) ///
     xtitle("Low Capacity                              High Capacity") xlabel(none) ///
title("Cyanide concentration by acute polluting mines")  ytitle("Average Treatment Effect") ylabel(-1(.5)1.5)


********************
* Appendix
********************

use resource_curse_merged.dta,clear
tsset department year
label_var1

*** Table A.1 

** 3. How do effects vary by institutional arrangement

eststo clear
xtreg ihs_ambiental cL.mineral_price_index i.year, fe vce(cl department)
eststo
xtreg ihs_ambiental cL.mineral_price_index##very_competitive i.year, fe vce(cl department)
eststo
xtreg ihs_ambiental cL.mineral_price_index##cL.pct_executed i.year, fe vce(cl department)
eststo
xtreg ihs_ambiental cL.mineral_price_index##very_competitive##cL.pct_executed i.year, fe vce(cl department)
eststo

esttab using "tablea1.tex", drop(*.year 0.*)   cells(b(star fmt(2)) se(par fmt(2))) stats(N, labels(N) fmt(0)) starlevel(* .05 ** .01 *** .001) replace tex nolz label noabb wrap varwidth(50) mtitles


*** Table A.2

eststo clear
xtreg ihs_ambiental cL.mineral_price_index cL.mineral_price_index#c.ihs_totalmines i.year, fe vce(cl department)
eststo
xtreg cL.mineral_price_index cL.mineral_price_index#c.ihs_totalmines i.year, fe vce(cl department)
eststo
xtreg ihs_beneficio cL.mineral_price_index cL.mineral_price_index#c.ihs_totalmines i.year, fe vce(cl department)
eststo

esttab using "tablea2.tex",  drop(*.year )   cells(b(star fmt(2)) se(par fmt(2))) stats(N, labels(N) fmt(0)) starlevel(* .05 ** .01 *** .001) replace tex nolz label noabb wrap varwidth(50) mtitles

*** Table A.3

eststo clear
xtreg ihs_ambiental  L.price_index_acute cL.price_index_acute#c.ihs_acute_total L.price_index_chronic cL.price_index_chronic#c.ihs_chronic_total i.year, fe vce(cl department)
eststo
esttab using "tablea3.tex", keep(L.price_index_acute cL.price_index_acute#c.ihs_acute_total L.price_index_chronic cL.price_index_chronic#c.ihs_chronic_total) ///
 cells(b(star fmt(2)) se(par fmt(2))) stats(N, labels(N) fmt(0)) starlevel(* .05 ** .01 *** .001) replace tex nolz label noabb wrap varwidth(50) mtitles

*** Table A.4
use pollution_dataset.dta, clear
tsset mine_id year

eststo clear

xtreg ph cL.mine_price_index##cL2.pct_executed cL.mine_price_index##cL2.pct_executed#c.acute i.year, fe vce(cl mine_id)
eststo
xtreg ln_cyanide_pollution cL.mine_price_index##cL2.pct_executed cL.mine_price_index##cL2.pct_executed#c.acute i.year, fe vce(cl mine_id)
eststo

esttab using "tablea4.tex", drop(*.year ) ///
 cells(b(star fmt(2)) se(par fmt(2))) stats(N, labels(N) fmt(0)) starlevel(* .05 ** .01 *** .001) replace tex nolz label noabb wrap varwidth(50) mtitles

*** Table A.5
use resource_curse_merged.dta,clear
tsset department year
label_var1

eststo clear
xtreg ihs_ambiental cL.mineral_price_index cL.mineral_price_index#c.post_eiti i.year, fe vce(cl department)
eststo
xtreg ihs_ambiental  c.L.mineral_price_index##cL.pct_executed c.L.mineral_price_index##cL.pct_executed#c.post_eiti i.year , fe vce(cl department)
eststo

esttab using "tablea5.tex",  drop(*.year )  cells(b(star fmt(2)) se(par fmt(2))) stats(N, labels(N) fmt(0)) starlevel(* .05 ** .01 *** .001) replace tex nolz label noabb wrap varwidth(50) mtitles

*** Table A.6

eststo clear
xtreg ihs_ambiental L.price_index_new2006  i.year, fe vce(cl department)
eststo
xtreg ihs_ambiental L.mineral_price_index   i.year, fe vce(cl department)
eststo
xtreg ihs_ambiental L.price_index_new2006  L.mineral_price_index i.year, fe vce(cl department)
eststo
esttab using "tablea6.tex",  drop(*.year)  cells(b(star fmt(2)) se(par fmt(2))) stats(N, labels(N) fmt(0)) starlevel(* .05 ** .01 *** .001) replace tex nolz label noabb wrap varwidth(50) mtitles

*** Table A.7

eststo clear

xtreg ihs_ambiental cL.mineral_price_index cL.mineral_price_index#election i.year , fe vce(cl department)
margins, dydx(L1.mineral_price_index) at(  election=(0 1 ) )

xtreg ihs_ambiental cL.mineral_price_index##cL.pct_executed cL.mineral_price_index##cL.pct_executed#election i.year , fe vce(cl department)
margins, dydx(L1.mineral_price_index) at( cL.pct_executed=(.84  .92 ) election=(0 1 ) )


*** Table A.8

eststo clear

foreach x in copper gas gold iron lead oil silver tin zinc{
xtreg ihs_ambiental cL.`x'_s#c.`x'_sum i.year , fe vce(cl department)
eststo
}

esttab using "tablea8.tex",  drop(*.year )  cells(b(star fmt(2)) se(par fmt(2))) stats(N, labels(N) fmt(0)) starlevel(* .05 ** .01 *** .001) replace tex nolz label noabb wrap varwidth(50) mtitles

*** Table A.10

eststo clear
xtreg ihs_ambiental cL.mineral_price_index ihs_ambiental_neighbor_total  i.year, fe vce(cl department)
eststo
xtreg ihs_ambiental cL.mineral_price_index ihs_non_mining_neighbor_total  i.year, fe vce(cl department)
eststo
xtreg ihs_ambiental cL.mineral_price_index ihs_non_mining_neighbor_total ihs_ambiental_neighbor_total  i.year, fe vce(cl department)
eststo

xtreg ihs_ambiental_neighbor_total cL.mineral_price_index   i.year, fe vce(cl department)
eststo
xtreg ihs_non_mining_neighbor_total cL.mineral_price_index  i.year, fe vce(cl department)
eststo

esttab using "tablea10.tex",  drop(*.year )  cells(b(star fmt(2)) se(par fmt(2))) stats(N, labels(N) fmt(0)) starlevel(* .05 ** .01 *** .001) replace tex nolz label noabb wrap varwidth(50) mtitles

*** Figure A.1

xtreg ihs_ambiental  cL.price_index_adj##cL.price_index_adj i.year, fe vce(cl department)
margins, dydx(cL.price_index_adj) at(cL.price_index_adj=(0(1)3) )

marginsplot, level(90)  yline(0) plotop(connect(none)  mcolor(gs2)   ) ciopts(lcolor(gs2)   lwidth(thick) lpattern(dash)  )   xscale(range(-.5(1)3.5 )) ///
xtitle("International Commodity Price (SD above minimum)") xlabel(0(1)3) ///
title("Conflict Events")  ytitle("Average Treatment Effect") 
graph export "diminish1.pdf",replace

*** Figure A.2

xtreg ihs_ambiental cL.mineral_price_index##cL.ln_non_mining  i.year, fe vce(cl department)
margins, dydx(L.mineral_price_index) at(L.ln_non_mining=(1(1) 4 ) ) post
marginsplot, yline(0) level(95) plotop(connect(none)  mcolor(gs2)   ) ciopts(lcolor(blue)   lwidth(thick) lpattern(dash)  )   xscale(range(.5 4.5)) ///
     xtitle("Logged non-mining protest incidents in previous year") xlabel(1(1)4) ///
title("")  ytitle("Average Treatment Effect") 
graph export "protest1.pdf",replace

*** Figure A.3

eststo clear

xtreg ihs_ambiental cL.mineral_price_index_domestic cL.mineral_price_index_mnc i.year, fe vce(cl department)
xtreg ihs_ambiental cL.mineral_price_index_domestic##very_competitive##cL.pct_executed cL.mineral_price_index_mnc##very_competitive##cL.pct_executed i.year, fe vce(cl department)
margins, dydx(L.mineral_price_index_mnc) at(very_competitive=(0 1 ) cL.pct_executed=(.84  .92 ))
margins, dydx(L.mineral_price_index_domestic) at(very_competitive=(0 1 ) cL.pct_executed=(.84  .92 ))

use margins_domestic.dta,clear

gen u=coef+(1.645*se)
gen l=coef-(1.645*se)

 twoway rcap u l position if competitive==0, lcolor(red)  lwidth(thick) lpattern(dash)  || ///
     rcap u l position if competitive==1, lcolor(blue)  lwidth(thick)lpattern(dash)  || ///
    scatter coef position ///
    ,  msymbol(0) mcolor(black) ///
     xtitle("Low Capacity                           High Capacity") ///
    yline(0, lc(black)) title("") xlabel(none)  ytitle("Average Treatment Effect") ///
	legend(order(2 1) label(1 "Not Competitive") label(2 "Competitive")) ylabel(-1.5(.5)1.5) title("Price index: Domestic firms")
graph export "domestic_margins.pdf",replace

use margins_multinational.dta,clear 

gen u=coef+(1.645*se)
gen l=coef-(1.645*se)

 twoway rcap u l position if competitive==0, lcolor(red)  lwidth(thick) lpattern(dash)  || ///
     rcap u l position if competitive==1, lcolor(blue)  lwidth(thick)lpattern(dash)  || ///
    scatter coef position ///
    ,  msymbol(0) mcolor(black) ///
     xtitle("Low Capacity                         High Capacity") ///
    yline(0, lc(black)) title("") xlabel(none)  ytitle("Average Treatment Effect") ///
	legend(order(2 1) label(1 "Not Competitive") label(2 "Competitive")) ylabel(-1.5(.5)1.5)  title("Price index: Foreign firms")
graph export "multinational_margins.pdf",replace

*** Table A.12
use resource_curse_merged.dta,clear
tsset department year
label_var1

eststo clear

xtreg combined_pc2 cL.mineral_price_index i.year, fe vce(cl department)
eststo
xtreg amount_per_mining_provice2 cL.mineral_price_index i.year, fe vce(cl department)
eststo
xtreg amount_per_mine2 cL.mineral_price_index  i.year, fe vce(cl department)
eststo
xtreg local_pc cL.mineral_price_index i.year, fe vce(cl department)
eststo
xtreg pbi_pc2 cL.mineral_price_index i.year, fe vce(cl department)
eststo

esttab using "tablea12.tex",  keep(L.mineral_price_index)  cells(b(star fmt(2)) se(par fmt(2))) stats(N, labels(N) fmt(0)) starlevel(* .05 ** .01 *** .001) replace tex nolz label noabb wrap varwidth(50) mtitles


*** Table A.13

eststo clear

xtreg ihs_ambiental L.price_index_acute cL.price_index_acute#c.ihs_acute_total L.price_index_chronic cL.price_index_chronic#c.ihs_chronic_total ///
L2.price_index_acute cL2.price_index_acute#c.ihs_acute_total L2.price_index_chronic cL2.price_index_chronic#c.ihs_chronic_total ///
 L3.price_index_acute  cL3.price_index_acute#c.ihs_acute_total L3.price_index_chronic cL3.price_index_chronic#c.ihs_chronic_total  i.year, fe vce(cl department)
eststo

esttab using "tablea13.tex",  drop(*.year)  cells(b(star fmt(2)) se(par fmt(2))) stats(N, labels(N) fmt(0)) starlevel(* .05 ** .01 *** .001) replace tex nolz label noabb wrap varwidth(50) mtitles


*** Figure A.4

use margins1.dta, clear

gen u=coef+(1.645*se)
gen l=coef-(1.645*se)

 twoway rcap u l position if competitive==0, lcolor(cranberry)  lwidth(thick) lpattern(dash)  || ///
     rcap u l position if competitive==1, lcolor(eltblue)  lwidth(thick)lpattern(dash)  || ///
    scatter coef position ///
    ,  msymbol(0) mcolor(black) ///
     xtitle("Low Capacity                                 High Capacity") ///
    yline(0, lc(black)) title("") xlabel(none)  ytitle("Average Treatment Effect") ///
	legend(order(2 1) label(1 "Not Competitive") label(2 "Competitive")) ylabel(-1(.5)1)
graph export "margins1.pdf",replace

*** Table A.14

use resource_curse_merged.dta,clear
tsset department year
label_var1

eststo clear
xtreg ihs_ambiental cL.mineral_price_index##cL.pct_executed cL2.mineral_price_index##cL2.pct_executed i.year, fe vce(cl department)
eststo
esttab using "tablea14.tex",  drop(*.year)  cells(b(star fmt(2)) se(par fmt(2))) stats(N, labels(N) fmt(0)) starlevel(* .05 ** .01 *** .001) replace tex nolz label noabb wrap varwidth(50) mtitles

*** Table A.15

xtreg ihs_ambiental c.L.mineral_price_index##very_competitive##cL.pct_executed c.F.mineral_price_index##very_competitive##cL.pct_executed i.year, fe vce(cl department)
margins, dydx(L1.mineral_price_index F1.mineral_price_index) at(very_competitive=(0 1) cL.pct_executed=(.84  .92 )) post

test [L.mineral_price_index]1._at - [F.mineral_price_index]1._at = 0
di 1-normal(sqrt(r(chi2)))

test [L.mineral_price_index]3._at - [F.mineral_price_index]3._at = 0
di 1-normal(sqrt(r(chi2)))

foreach y in  non_mining clash  {
xtreg ihs_`y' c.L.mineral_price_index##very_competitive##cL.pct_executed i.year, fe vce(cl department)
eststo
margins, dydx(L1.mineral_price_index) at(very_competitive=(0 1) cL.pct_executed=(.84 .92 ))
}

*** Table A.16

eststo clear
xtreg very_competitive L.mineral_price_index i.year, fe vce(cl department)
eststo
xtreg L.pct_executed L.mineral_price_index  i.year if year>2006 & year<2015, fe vce(cl department)
eststo
xtreg very_competitive ihs_ambiental i.year, fe vce(cl department)
eststo
xtreg  L.pct_executed ihs_ambiental i.year, fe vce(cl department)
eststo
xtreg  L.pct_executed very_competitive i.year if year>2006, fe vce(cl department)
eststo

esttab using "tablea16.tex",  drop(*.year )  cells(b(star fmt(2)) se(par fmt(2))) stats(N, labels(N) fmt(0)) starlevel(* .05 ** .01 *** .001) replace tex nolz label noabb wrap varwidth(50) mtitles


*** Table A.17

eststo clear
xtreg ihs_ambiental c.L_mineral_price_index##very_competitive##c.L_pct_executed i.year, fe vce(cl department)
margins, dydx(L_mineral_price_index) at(very_competitive=(0 1) L_pct_executed=(.84  .92 ))
eststo

xtset department

qui bootstrap, reps(1000) cluster(department) seed(123): xtreg ihs_ambiental c.L_mineral_price_index##very_competitive##c.L_pct_executed i.year, fe 
eststo
margins, dydx(L_mineral_price_index) at(very_competitive=(0 1) L_pct_executed=(.84  .92 ))

*** Figure A.5

use resource_curse_merged.dta,clear
tsset department year
label_var1

qui xtreg ambiental  c.L.mineral_price_index##very_competitive i.year, fe vce(cl department)
margins, dydx(L1.mineral_price_index) at(very_competitive=(0 1) )
marginsplot, yline(0) plotop(connect(none)  mcolor(gs2)   ) ciopts(lcolor(gs2)   lwidth(thick) lpattern(dash)  )   xscale(range(-0.5 1.5)) ///
xtitle("Low Competition                                High Competition") xlabel(none) ///
title("Event Counts with OLS")  ytitle("Average Treatment Effect")
graph export "figurea5_1.pdf",replace

qui xtreg ambiental  c.L.mineral_price_index##cL2.pct_executed i.year, fe vce(cl department)
margins, dydx(L1.mineral_price_index) at(cL2.pct_executed=(.84 .88 .92 ) )
marginsplot, yline(0) plotop(connect(none)  mcolor(gs2)   ) ciopts(lcolor(gs2)   lwidth(thick) lpattern(dash)  )   xscale(range(0.82 0.94)) ///
     xtitle("Low Capacity              Medium Capacity                High Capacity") xlabel(none) ///
title("Event Counts with OLS")  ytitle("Average Treatment Effect")
graph export "figurea5_2.pdf",replace

qui xtreg ambiental2  c.L.mineral_price_index##very_competitive i.year, fe vce(cl department)
margins, dydx(L1.mineral_price_index) at(very_competitive=(0 1) )
marginsplot, yline(0) plotop(connect(none)  mcolor(gs2)   ) ciopts(lcolor(gs2)   lwidth(thick) lpattern(dash)  )   xscale(range(-0.5 1.5)) ///
xtitle("Low Competition                                High Competition") xlabel(none) ///
title("Binary Outcome with OLS")  ytitle("Average Treatment Effect")
graph export "figurea5_3.pdf",replace

qui xtreg ambiental2  c.L.mineral_price_index##cL2.pct_executed i.year, fe vce(cl department)
margins, dydx(L1.mineral_price_index) at(cL2.pct_executed=(.84 .88 .92 ) )
marginsplot, yline(0) plotop(connect(none)  mcolor(gs2)   ) ciopts(lcolor(gs2)   lwidth(thick) lpattern(dash)  )   xscale(range(0.82 0.94)) ///
     xtitle("Low Capacity              Medium Capacity                High Capacity") xlabel(none) ///
title("Binary Outcome with OLS")  ytitle("Average Treatment Effect")
graph export "figurea5_4.pdf",replace

qui poisson ambiental  c.L.mineral_price_index##very_competitive i.year i.department,  vce(cl department)
margins, dydx(L1.mineral_price_index) at(very_competitive=(0 1) )
marginsplot, yline(0) plotop(connect(none)  mcolor(gs2)   ) ciopts(lcolor(gs2)   lwidth(thick) lpattern(dash)  )   xscale(range(-0.5 1.5)) ///
xtitle("Low Competition                                High Competition") xlabel(none) ///
title("Poisson Regression")  ytitle("Average Treatment Effect") 
graph export "figurea5_5.pdf",replace

qui poisson ambiental  c.L.mineral_price_index##cL2.pct_executed i.year i.department,  vce(cl department)
margins, dydx(L1.mineral_price_index) at(cL2.pct_executed=(.84 .88 .92 ) )
marginsplot, yline(0) plotop(connect(none)  mcolor(gs2)   ) ciopts(lcolor(gs2)   lwidth(thick) lpattern(dash)  )   xscale(range(0.82 0.94)) ///
     xtitle("Low Capacity              Medium Capacity                High Capacity") xlabel(none) ///
title("Poisson Regression")  ytitle("Average Treatment Effect")
graph export "figurea5_6.pdf",replace

*** Table A.18

xtreg ihs_enviro cL.mineral_price_index##very_competitive##cL.pct_executed i.year, fe vce(cl department)
margins, dydx(L1.mineral_price_index) at(very_competitive=(0 1 ) cL.pct_executed=(.84  .92 ) ) post

xtreg ihs_rechazo cL.mineral_price_index##very_competitive##cL.pct_executed i.year, fe vce(cl department)
margins, dydx(L1.mineral_price_index) at(very_competitive=(0 1 ) cL.pct_executed=(.84  .92 ) ) post

xtreg ihs_beneficio cL.mineral_price_index##very_competitive##cL.pct_executed i.year, fe vce(cl department)
margins, dydx(L1.mineral_price_index) at(very_competitive=(0 1 ) cL.pct_executed=(.84  .92 ) ) post

*** Table A.19

use china_imports.dta,clear
tsset commodity year

eststo clear
xtreg price trade L.trade i.year ,  vce(cl commodity)
eststo
esttab using "appendixD1.tex",  drop(*.year)  cells(b(star fmt(2)) se(par fmt(2))) stats(N, labels(N) fmt(0)) starlevel(* .05 ** .01 *** .001) replace tex nolz label noabb wrap varwidth(50) mtitles

*** Appendix E

use institutions.dta, clear

tab hi_reg_quality if developing==1 & resource_rents05_14>10
tab hi_reg_quality if developing==1 & resource_rents05_14>5

tab hi_local_impact if developing==1 & resource_rents05_14>10
tab hi_local_impact if developing==1 & resource_rents05_14>5

tab subnational_sharing1  if developing==1 & resource_rents05_14>10
tab subnational_sharing1  if developing==1 & resource_rents05_14>5

tab super_institutions if developing==1 & resource_rents05_14>10
tab super_institutions if developing==1 & resource_rents05_14>5



